package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.TeacherRoleMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.RoleExample;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.TeacherRole;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.TeacherRoleExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherRoleServiceImpl implements ITeacherRoleService{
    @Autowired
    private TeacherRoleMapper teacherRoleMapper;
    @Override
    public Integer insertTeacherRole(TeacherRole teacherRole) {
        return teacherRoleMapper.insert(teacherRole);
    }

    @Override
    public Integer deleteTeacherRoleByPrimaryId(Integer roleId) {
        return teacherRoleMapper.deleteByPrimaryKey(roleId);
    }

    @Override
    public Integer updateTeacherRoleByPrimaryId(TeacherRole teacherRole) {
        return teacherRoleMapper.updateByPrimaryKey(teacherRole);
    }

    @Override
    public List<TeacherRole> queryTeacherRolesByIds(List<Integer> ids) {
        return null;
    }

    @Override
    public List<TeacherRole> queryAllTeacherRole() {
        TeacherRoleExample example = new TeacherRoleExample();
        TeacherRoleExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        return teacherRoleMapper.selectByExample(example);
    }

    @Override
    public TeacherRole queryTeacherRolesById(Integer id) {
        return teacherRoleMapper.selectByPrimaryKey(id);
    }

    @Override
    public int queryTeacherRoleCount() {
        TeacherRoleExample teacherRoleExample = new TeacherRoleExample();
        TeacherRoleExample.Criteria criteria = teacherRoleExample.createCriteria();
        criteria.getAllCriteria();
        return (int) teacherRoleMapper.countByExample(teacherRoleExample);
    }

    @Override
    public List<TeacherRole> queryTeacherRoleByPage(int pageNow, int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<TeacherRole> roles = this.queryAllTeacherRole();
        PageInfo<TeacherRole> teacherRolePageInfo = new PageInfo<>(roles);
        return teacherRolePageInfo.getList();
    }
}
